//
//  YDRechargeWithdrawalButtonView.m
//  PeiZiWangBei
//
//  Created by LK-IOS on 2017/11/14.
//  Copyright © 2017年 LK-IOS. All rights reserved.
//

#import "YDRechargeWithdrawalButtonView.h"

@interface YDRechargeWithdrawalButtonView()

//按钮
@property (nonatomic , weak) SYNoHeightedButton *button;

@end


@implementation YDRechargeWithdrawalButtonView

-(void)disableButton
{
    self.button.enabled = NO;
}

-(void)enableButton
{
    self.button.enabled = YES;
}

-(void)setButtonTitle:(NSString *)buttonTitle
{
    _buttonTitle = buttonTitle;
    
    //设置标题
    [self.button setTitle:buttonTitle forState:UIControlStateNormal];
    [self.button setTitle:buttonTitle forState:UIControlStateDisabled];
}
-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
    
        [self button];
        
    }
    return self;
}

+(instancetype)rechargeWithdrawalButtonWithButtonTitle:(NSString *)buttonTitle
{
    YDRechargeWithdrawalButtonView *buttonView = [[self alloc] init];
    buttonView.buttonTitle = buttonTitle;
    return buttonView;
}


-(SYNoHeightedButton *)button
{
    if (_button == nil) {
        SYNoHeightedButton *button = [SYNoHeightedButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:button];
        [button setBackgroundImage:[UIImage imageWithColor:zhidianAlprColor(0.3)] forState:UIControlStateDisabled];
        [button setBackgroundImage:[UIImage imageWithColor:zhidainMainColor] forState:UIControlStateNormal];
        [button setTitle:self.buttonTitle forState:UIControlStateNormal];
        [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [button setTitleColor:[UIColor whiteColor] forState:UIControlStateDisabled];
        button.titleLabel.font = [UIFont systemFontOfSize:font16ScreenWRate * LKScreenW];
        button.titleLabel.textAlignment = NSTextAlignmentCenter;
        [button mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.bottom.equalTo(self);
        }];
        button.enabled = NO;
        [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchDown];
        _button = button;
    }
    return _button;
}
-(void)buttonClick:(SYNoHeightedButton *)button
{
    if ([self.delegate respondsToSelector:@selector(rechargeWithdrawalButtonViewButtonClick)]) {
        [self.delegate rechargeWithdrawalButtonViewButtonClick];
    }
}
@end
